package org.lyu.dao.impl;

import java.util.List;

import org.lyu.dao.IPetDao;
import org.lyu.entity.Pet;
import org.lyu.util.MyDbUtils3;

/**
 * 增删改查的dao
 * 
 * @author Administrator
 *
 */
public class PetDao3 implements IPetDao {
		
	public List<Pet> getAll() {
		String sql = "select * from pet";
		return MyDbUtils3.excuteQueryForList(Pet.class, sql);
	}
	
	public int add(Pet pet) {
		String sql = "insert into pet(name,owner,species,sex,birth,death) values (?,?,?,?,?,?)";
		return MyDbUtils3.excuteUpdate(sql, pet.getName(), pet.getOwner(), pet.getSpecies(), pet.getSex(), pet.getBirth(), pet.getDeath());
	}

	public int update(Pet pet) {
		
		String sql = " update pet set owner=?,species=?,sex=?,birth=?,death=? where name = ? ";
		return MyDbUtils3.excuteUpdate(sql, pet.getOwner(), pet.getSpecies(), pet.getSex(), pet.getBirth(), pet.getDeath(), pet.getName());

	}

	public int delete(String petName) {
		String sql = " delete from pet where name = ? ";
		return MyDbUtils3.excuteUpdate(sql, petName);
	}

	
	public Pet getByName(String petName) {
		String sql = " select * from pet where name = ? ";
		return MyDbUtils3.excuteQueryForOne(Pet.class, sql, petName);
	}
	
}
